module dungeon.weapon;

import nade.ast;
import nade.loader;

import dungeon.game;
import dungeon.stats;
import dungeon.equipment;
import dungeon.attack;


enum WeaponType {
	DAGGER,
	SWORD,
	AXE,
	BLUNT,
	SPIKED,
	STAFF,
	SPEAR,
	SCYTHE,
	THROWN,
	BOW,
	CROSSBOW,
	SLING,
}


class Weapon : Equipment {
	this(Game game)
	{
		super(game);
	}

	WeaponType weaponType() { return _weaponType; }
	Attack attack() { return _attack; }

	protected {
		WeaponType		_weaponType;
		Attack			_attack;
	}

	static void install()
	{
		Loader!(Weapon).add("type",
			(ref Weapon weapon, AST ast, Object[string] state) {
				weapon._weaponType = weaponTypeByName(ast[1].as!string);
			}
		);

		Loader!(Weapon).add("attack",
			(ref Weapon weapon, AST ast, Object[string] state) {
				weapon._attack = weapon._game.getAttack(ast, state);
			}
		);
	}
}


WeaponType weaponTypeByName(string name)
{
	switch(name)
	{
		case "dagger": return WeaponType.DAGGER;
		case "sword": return WeaponType.SWORD;
		case "axe": return WeaponType.AXE;
		case "blunt": return WeaponType.BLUNT;
		case "spiked": return WeaponType.SPIKED;
		case "staff": return WeaponType.STAFF;
		case "spear": return WeaponType.SPEAR;
		case "scythe": return WeaponType.SCYTHE;
		case "thrown": return WeaponType.THROWN;
		case "bow": return WeaponType.BOW;
		case "crossbow": return WeaponType.CROSSBOW;
		case "sling": return WeaponType.SLING;

		default:
	}

	assert(false);
}
